C
C     ..................................................................
C
C        SUBROUTINE BOUND
C
C        PURPOSE
C           SELECT FROM A SET (OR A SUBSET) OF OBSERVATIONS THE NUMBER
C           OF OBSERVATIONS UNDER, BETWEEN AND OVER TWO GIVEN BOUNDS
C           FOR EACH VARIABLE
C
C        USAGE
C           CALL BOUND (A,S,BLO,BHI,UNDER,BETW,OVER,NO,NV,IER)
C
C        DESCRIPTION OF PARAMETERS
C           A     - OBSERVATION MATRIX, NO BY NV
C           S     - VECTOR INDICATING SUBSET OF A. ONLY THOSE
C                   OBSERVATIONS WITH A NON-ZERO S(J) ARE CONSIDERED.
C                   VECTOR LENGTH IS NO.
C           BLO   - INPUT VECTOR OF LOWER BOUNDS ON ALL VARIABLES.
C                   VECTOR LENGTH IS NV.
C           BHI   - INPUT VECTOR OF UPPER BOUNDS ON ALL VARIABLES.
C                   VECTOR LENGTH IS NV.
C           UNDER - OUTPUT VECTOR INDICATING, FOR EACH VARIABLE, NUMBER
C                   OF OBSERVATIONS UNDER LOWER BOUNDS. VECTOR LENGTH
C                   IS NV.
C           BETW  - OUTPUT VECTOR INDICATING, FOR EACH VARIABLE, NUMBER
C                   OF OBSERVATIONS EQUAL TO OR BETWEEN LOWER AND UPPER
C                   BOUNDS. VECTOR LENGTH IS NV.
C           OVER  - OUTPUT VECTOR INDICATING, FOR EACH VARIABLE, NUMBER
C                   OF OBSERVATIONS OVER UPPER BOUNDS. VECTOR LENGTH
C                   IS NV.
C           NO    - NUMBER OF OBSERVATIONS
C           NV    - NUMBER OF VARIABLES FOR EACH OBSERVATION
C           IER   - ZERO, IF NO ERROR.
C                 - 1, IF LOWER BOUND IS GREATER THAN THE UPPER BOUND
C                   FOR SOME VARIABLE
C
C        REMARKS
C           NONE
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           NONE
C
C        METHOD
C           EACH ROW (OBSERVATION) OF MATRIX A WITH CORRESPONDING
C           NON-ZERO ELEMENT IN S VECTOR IS TESTED. OBSERVATIONS ARE
C           COMPARED WITH SPECIFIED LOWER AND UPPER VARIABLE BOUNDS AND
C           A COUNT IS KEPT IN VECTORS UNDER, BETWEEN, AND OVER.
C
C     ..................................................................
C
      SUBROUTINE BOUND(A,S,BLO,BHI,UNDER,BETW,OVER,NO,NV)
      DIMENSION A(1),S(1),BLO(1),BHI(1),UNDER(1),BETW(1),OVER(1)
C
C        CLEAR OUTPUT VECTORS.
C
      IER=0
      DO 10 I=1,NV
      IF (BLO(I)-BHI(I)) 10,10,11
   11 IER=1
      GO TO 12
   10 CONTINUE
      DO 1 K=1,NV
      UNDER(K)=0.0
      BETW(K)=0.0
    1 OVER(K)=0.0
C
C        TEST SUBSET VECTOR
C
      DO 8 J=1,NO
      IJ=J-NO
      IF(S(J)) 2,8,2
C
C        COMPARE OBSERVATIONS WITH BOUNDS
C
    2 DO 7 I=1,NV
      IJ=IJ+NO
      IF(A(IJ)-BLO(I)) 5,3,3
    3 IF(A(IJ)-BHI(I)) 4,4,6
C
C       COUNT
C
    4 BETW(I)=BETW(I)+1.0
      GO TO 7
    5 UNDER(I)=UNDER(I)+1.0
      GO TO 7
    6 OVER(I)=OVER(I)+1.0
    7 CONTINUE
    8 CONTINUE
   12 RETURN
      END
